<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .layui-elem-quote {
        padding: 5px;
        margin-bottom: 15px;
        border-left: 5px solid var(--primary-color);
        font-weight: 600;
    }

    .delthumb {
        position: absolute;
        right: 0;
        z-index: 999;
        cursor: pointer;
        display: none;
    }

    .thumb_control {
        display: block;
    }

    .element_title {
        font-weight: 600;
        color: var(--primary-color);
    }
</style>
<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding ">
        <form class="layui-form" action="" id="addform">
            <div class=" rc-pannel ">
                <div class=" rc-pannel-header rc-pagepadding rc-bold"> <i class="iconfont goback rc-pointer">&#xe62b;</i> 发布内容</div>
                <div class="rc-pannel-body ">
                    <div class="rc-flex">
                        <div class="rc-flex1 rc-pagepadding">


                            <div class="layui-form-item">
                                <label class="layui-form-label element_title">栏目：</label>
                                <div class="layui-input-block" style="line-height: 30px;">
                                    <?php echo $cateinfo['title']; ?>

                                    <input type="hidden" value="<?php echo request()->get('cid') ?>" name="cid" />

                                </div>

                            </div>

                            <?php
                            if (isset($fields[1])) {
                                foreach ($fields[1] as $field) {
                            ?>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label element_title"><?php echo $field['title'] ?>：</label>
                                        <div class="layui-input-block">

                                            <?php
                                            $element = $field['element'];
                                            unset($field['element']);
                                            unset($field['id']);
                                            $field['value'] = $field['default'];
                                            echo element($element, ...$field);

                                            ?>
                                        </div>

                                    </div>
                            <?php
                                }
                            } ?>



                            <!---  设置标签  --->
                            <?php
                            if ($tags) {
                            ?>

                                <div class="layui-form-item">
                                    <label class="layui-form-label element_title">标签：</label>
                                    <div class="layui-input-block">

                                        <?php
                                        foreach ($tags as $tag) {
                                        ?>
                                            <input type="checkbox" value="<?php echo $tag['id'] ?>" name="tag[]" title="<?php echo $tag['tag'] ?>" />
                                        <?php
                                        }
                                        ?>
                                    </div>

                                </div>
                            <?php
                            }
                            ?>




                        </div>
                        <div style="width: 240px;border-left:1px solid #ccc ">

                            <?php
                            if (isset($fields[2])) {
                                foreach ($fields[2] as $field) {

                            ?>
                                    <div class="layui-form-item rc-pagepadding" style="border-bottom: 1px solid #ccc;">
                                        <div style="margin-bottom: 15px;" class="element_title">
                                            <?php echo $field['title'] ?>
                                        </div>

                                        <div style="text-align: center;">
                                            <?php
                                            $element = $field['element'];
                                            unset($field['element']);
                                            unset($field['id']);
                                            $field['value'] = $field['default'];
                                            echo element($element, ...$field) ?>
                                        </div>

                                    </div>

                            <?php
                                }
                            } ?>


                            <div class="layui-form-item rc-pagepadding" style="border-bottom: 1px solid #ccc;">
                                <div style="margin-bottom: 15px;" class="element_title">
                                    浏览量
                                </div>
                                <div style="text-align: center;">
                                    <?php echo element('input', name: 'viewscount', value: 1); ?>
                                </div>
                            </div>

                            <div class="layui-form-item rc-pagepadding" style="border-bottom: 1px solid #ccc;">

                                <div style="margin-bottom: 15px;" class="element_title">
                                    是否允许评论/点赞/收藏
                                </div>
                                <div style="margin-bottom: 15px;" class="">
                                    <input type="radio" name="interacttype" title="跟随栏目" lay-filter="interacttype" value="1" checked autocomplete="off" />
                                    <input type="radio" name="interacttype" title="自定义" lay-filter="interacttype" value="2" autocomplete="off" />
                                </div>


                                <div style="text-align: center;display:none" id="interactcustom">
                                    <input type="checkbox" name="comment" title="评论" autocomplete="off"  value="1" autocomplete="off" />
                                    <input type="checkbox" name="praise" title="点赞" autocomplete="off"  value="1" autocomplete="off" />
                                    <input type="checkbox" name="collect" title="收藏" autocomplete="off"  value="1" autocomplete="off" />
                                </div>

                            </div>


                        </div>

                    </div>

                </div>

                <div class="rc-pannel-footer rc-pagepadding" style="text-align: center;">

                    <div class="">
                        <input type="hidden" value="<?php echo request()->get('cid') ?>" name="cid" />
                        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="submit">提交</button>
                        <button type="reset" class="layui-btn layui-btn-sm">重置</button>
                    </div>

                </div>
            </div>
        </form>
    </div>

    <script type='text/javascript'>
        layui.use(function() {

            var form = layui.form;
            var layer = layui.layer;

            form.on('radio(interacttype)', function(data) {

                var elem = data.elem; // 获得 radio 原始 DOM 对象
                var checked = elem.checked; // 获得 radio 选中状态
                var value = elem.value; // 获得 radio 值
                var othis = data.othis; // 获得 radio 元素被替换后的 jQuery 对象

                if (value == 2) {
                    $('#interactcustom').show();
                } else {
                    $('#interactcustom').hide();
                }

            });


            form.on('submit(submit)', function(data) {
                $.ajax({
                    url: '/app/cms/admin/Index/add', //请求路径
                    type: "POST", //请求方式
                    data: data.field, // 默认写法
                    success: function(data) {
                        if (data.code == 0) {
                            toastr_success("添加成功", function() {
                                window.location.href = '/app/cms/admin/Index/index?cid=<?php echo request()->get('cid') ?>';
                            });
                        } else {
                            toastr_error(data.message);
                        }
                    },
                    error: function() {

                    },

                });

                return false; // 阻止默认 form 跳转

            });

        });
    </script>